import {Injectable} from '@angular/core';
import {HttpClient} from '@angular/common/http';
import {tap} from 'rxjs/operators';
import {pipe} from 'rxjs';

@Injectable({
  providedIn: 'root'
})
export class ManageService {
  serviceUrl = {
    exportUrl: '/adzOrder/getOrderExcel', // 订单管理导出
    dictUrl: '/dict/detail', // 查询渠道
    imgList: '/adzImage/list', // 图片查询
    imgAdd: '/adzImage/save', // 图片添加
    imgCategory: '/adzImageType/list', // 图片分类
    imgCategoryAdd: '/adzImageType/save', // 添加图片分类
    imgStatus: '/adzImageType/isEnable', // 图片分类禁用启用
    orderList: '/adzOrder/list', // 订单列表
    orderDetail: '/adzOrderDetails', // 订单列表
    orderRefund: '/adzOrderDetails/refundOrder', // 退款
    orderTrack: '/adzOrderDetails/follow', // 订单跟进
    orderCancel: '/adzOrderDetails/cancelOrder', // 取消订单
    orderModifyAddress: '/adzOrder/updateUserAddress', // 修改订单收货地址
    fileUpload: '/common/upload/file', // 文件上传

    updatePriceUrl: '/adzOrder/updatePrice', // 订单改价
    updateSignUrl: '/adzOrderDetails/sign' // 标记 | 取消标记
  };

  constructor(private httpClient: HttpClient) {
  }

  httpGet(url: string, params: any) {
    return this.httpClient.get(url, {params}).toPromise();
  }

  httpPost(url: string, body: any) {
    // return this.httpClient.post(url, body).toPromise().then((res: any) => {
    //   return res.code === 0 ? res.data : {current: 0, pages: 0, records: [], searchCount: 0, size: 0, total: 0};
    // });
    return this.httpClient.post(url, body).toPromise();
  }

  // 爱定制订单改价
  updatePriceData(params: any) {
    return this.httpClient.post(this.serviceUrl.updatePriceUrl, params).toPromise();
  }

  // 爱定制订单详情--标记 | 取消标记
  updateSignData(params: any) {
    return this.httpClient.post(this.serviceUrl.updateSignUrl, params).toPromise();
  }

  // 查询渠道（字典）
  dictData(parentKey: any) {
    const params: any = {
      pageNum: 1,
      pageSize: 999,
      parentKey
    }
    return this.httpClient.get(this.serviceUrl.dictUrl, { params }).toPromise();
  }

  // 订单管理导出
  orderManageExport(params: any) {
    return this.httpClient.get(this.serviceUrl.exportUrl, { params });
  }
}
